package client.domain.ui.global;

import static client.domain.SandboxMainKeys.DEFAULT_VERTICAL_SPACE_BETWEEN_WIDGETS;
import client.internationalization.SandboxConstants;
import client.internationalization.SandboxMessages;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
import com.gwtext.client.core.EventObject;
import com.gwtext.client.widgets.Button;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.Window;
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
import com.gwtext.client.widgets.layout.VerticalLayout;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * User: nbarrios
 * Date: Nov 17, 2009
 */
public class ErrorsPopUp extends Window{

	//	Internationalization Strings
	private SandboxConstants constants = GWT.create(SandboxConstants.class);
	private SandboxMessages messages = GWT.create(SandboxMessages.class);

	//  Attributes
	private Panel panel = new Panel();
	private List errors = new ArrayList();
	private List warnings = new ArrayList();

	// Constructor
	/**
	 * Creates a new Errors Pop Up
	 * @param errorsList
	 * @param warningsList
	 */
	public ErrorsPopUp(List errorsList, List warningsList) {
		super();

		this.errors = errorsList;
		this.warnings = warningsList;

		this.setTitle(constants.errorsWindowTitle());
		this.setSize("600", "600");
		this.setClosable(true);
		this.setPlain(true);
		this.setLayout(new VerticalLayout());
		this.setCloseAction(Window.CLOSE);

		panel.setLayout(new VerticalLayout(DEFAULT_VERTICAL_SPACE_BETWEEN_WIDGETS));
		panel.setBorder(false);

		
		Button confirmButton = new Button("Aceptar");
		confirmButton.addListener(new ButtonListenerAdapter() {
			public void onClick(Button button, EventObject e) {
				close();//	Close the Pop Up
			}
		});

		//	Add the errors
		if(errors!=null)
			for(Iterator it = this.errors.iterator();it.hasNext();){
				panel.add((Widget)it.next());
			}

		//	Add the warnings
		if(warnings!=null)
			for(Iterator it = this.warnings.iterator();it.hasNext();){
				panel.add((Widget)it.next());
			}

		panel.add(confirmButton);

		this.add(panel);
	}

	//  Getters & Setters
	public List getErrors() {
		return errors;
	}

	public void setErrors(List errors) {
		this.errors = errors;
	}

	public List getWarnings() {
		return warnings;
	}

	public void setWarnings(List warnings) {
		this.warnings = warnings;
	}

}//  End Class
